/**  
 * @Title ApayNotifyCtrl.java
 * @date 2016年4月26日 上午10:16:38
 * @Copyright (c) 2016, unibroad.com Inc. All rights reserved.
 */
package pay.ctrl;

import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;

import base.ctrl.BaseController;
import base.jfinal.anatation.RouteBind;
import pay.biz.Dispatcher;
import pay.biz.PayTypeEnum;

/**
 * @Description 微信支付回调
 * @Class pay.ctrl.WxPayInteractiveCtrl
 * @author suan@unibroad.com
 * @version V1.0
 */
@RouteBind(path = "wxpay")
public class WxPayInteractiveCtrl extends BaseController {

    /**
     * 微信通知相关调用回调接口
     * 
     * <pre>
     * </pre>
     */
    public void notifymsg() {

        // 1. 获取参数,这里需要转码参数
        String content = "", respMsg = "";

        try {
            final InputStream in = this.getRequest().getInputStream();
            byte[] buf = new byte[this.getRequest().getContentLength()];
            in.read(buf);
            content = new String(buf, "UTF-8");
            log.info("wx notify req params=" + content);
            in.close();
            Map<String, String> params = new HashMap<String, String>();
            params.put("content", content);
            Dispatcher.getBizExecutor(PayTypeEnum.WX_MOBILE, params).execute(params);
            getResponse().setStatus(200);
            respMsg = "<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg> </xml>";
        } catch (Exception e) {
            log.error("wx notify req exception", e);
            getResponse().setStatus(500);
        } finally {
            renderText(respMsg);
        }

    }

}
